from django.db import models


class UserInfo(models.Model):
    '''
    用户信息
    '''
    name = models.CharField(verbose_name='姓名', max_length=32)
    age = models.CharField(max_length=11, verbose_name='年龄')
    gender = models.CharField(max_length=11, verbose_name='性别')
    email = models.EmailField(verbose_name='邮箱')
    phone = models.CharField(verbose_name='手机', max_length=32)

    class Meta:
        verbose_name_plural = '用户表'

    def __str__(self):
        return self.name


class UserGroup(models.Model):
    '''
    用户组
    '''
    name = models.CharField(max_length=32, verbose_name='组名')
    users = models.ManyToManyField('UserInfo', verbose_name='组成员')

    class Meta:
        verbose_name_plural = '用户组表'

    def __str__(self):
        return self.name


class BusinessUnit(models.Model):
    '''
    业务线
    '''
    name = models.CharField(max_length=32)
    contact = models.ForeignKey('UserGroup', verbose_name='业务联系人')
    manager = models.ForeignKey('UserGroup', verbose_name='管理人员', related_name='aaa')

    class Meta:
        verbose_name_plural = '业务线表'

    def __str__(self):
        return self.name


class Server(models.Model):
    '''
    服务器
    '''
    # asset = models.OneToOneField('Asset')
    hostname = models.CharField(max_length=32, unique=True)
    sn = models.CharField(max_length=64, db_index=True)
    manufacturer = models.CharField(max_length=64, verbose_name='制造商', null=True, blank=True)
    model = models.CharField(max_length=64, verbose_name='型号', blank=True, null=True)
    manage_ip = models.GenericIPAddressField(verbose_name='管理IP', null=True, blank=True)

    os_platform = models.CharField(max_length=32, verbose_name='系统', null=True, blank=True)
    os_version = models.CharField(max_length=32, verbose_name='系统版本', null=True, blank=True)

    cpu_count = models.IntegerField(verbose_name='CPU数量', null=True, blank=True)
    cpu_physical = models.IntegerField(verbose_name='CPU物理数量', null=True, blank=True)
    cpu_model = models.CharField(max_length=128, verbose_name='CPU型号', null=True, blank=True)

    create_time = models.DateTimeField(auto_now_add=True, blank=True)

    class Meta:
        verbose_name_plural = "服务器表"

    def __str__(self):
        return self.hostname